package com.example.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
/*配置Jwt的拦截器、固定配置*/
@Configuration
public class WebConfig implements  WebMvcConfigurer {

    @Resource
    private JwtInterceptor jwtInterceptor;/*拦截器通过这个配置类生效*/

    // 加自定义拦截器JwtInterceptor，设置拦截规则
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor).addPathPatterns("/**")/*拦截所有请求*/
                /*排除登录、注册、文件下载*/
                .excludePathPatterns("/")
                .excludePathPatterns("/login")/*因为登录注册时还没有token*/
                .excludePathPatterns("/register")
                .excludePathPatterns("/files/**");/*文件下载加token会比较麻烦*/

    }
}